import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
} from "typeorm";
import UserInterface from "src/utils/interfaces/user.interface";
import { Company } from "src/modules/company/company.entity";
import { Order } from "src/modules/order/order.entity";
import { Delivery } from "src/modules/delivery/delivery.entity";
import { Log } from "src/modules/log/log.entity";

@Entity()
export class User {
  @PrimaryGeneratedColumn("uuid")
  id: string;

  @Column({ nullable: false, unique: true })
  username: string;

  @Column()
  password: string;

  @Column({ nullable: true })
  name: string;

  @CreateDateColumn()
  date: Date;

  @Column({ nullable: true })
  role: UserInterface.Role;

  @OneToMany(() => Order, (order) => order.user)
  orders: Order[];

  @OneToMany(() => Delivery, (delivery) => delivery.user)
  deliveries: Delivery[];

  @OneToMany(() => Log, (log) => log.user)
  logs: Log[];

  @ManyToOne(() => Company, (company) => company.users)
  company: Company;
}
